package com.bcmusic.pay;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;


/**
 * @ClassName : PayApplication  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-10-14 14:29  //时间
 */

//这个注解是使用feign才加的，，吐血
//@EnableFeignClients(basePackages = {"com.bcmusic.pay.feign"})
//其它微服务通过名称调用该微服务需要加上这个
@EnableDiscoveryClient
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableEurekaClient
public class PayApplication {
    @Autowired
    private Environment env;

    /**
     * 队列
     * @return
     */
    @Bean
    public Queue CreateQueue(){
        return new Queue(env.getProperty("mq.pay.queue.order"),true);
    }

    /**
     * 直接交换机，其它消息会被丢弃
     * @return
     */
    @Bean
    public DirectExchange basicExchange(){
        return new DirectExchange(env.getProperty("mq.pay.exchange.order"),true,false);
    }

    /**
     * 绑定
     * @return
     */
    @Bean
    public Binding basicBindingOrder()
    {
        return BindingBuilder.bind(CreateQueue()).to(basicExchange()).with(env.getProperty("mq.pay.routing.key"));
    }


    public static void main(String[] args) {
        SpringApplication.run(PayApplication.class,args);
    }

}
